<%--
    Copyright 2010 mazhao.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    under the License.
    Document   : checkout.jsp
    Created on : Oct 16, 2010, 8:47:00 PM
    Author     : mazhao
--%>

<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><s:text name="checkout.html.title" /></title>
    <script type="text/javascript">

        $(document).ready(function() {
            summary();
        });

        function summary() {
            $.log("summary begin");
            var sum = 0;
            var sumMoney = 0.0;

            $("table#checkoutTable tbody tr").each(function(i) {
                var curCnt = parseInt($(this).children(":nth-child(2)").text())
                var curMoney = parseFloat($(this).children(":nth-child(3)").text())
                $.log("add each " + curCnt + " " + curMoney);

                sum += curCnt;
                sumMoney += curMoney

            });

            $("#summary").html(sum);
            $("#summaryMoney").html(sumMoney);

            $.log("summary end");
        }

    </script>
</head>
<body>
<h2><s:text name="checkout.title"/> </h2>

<div id="orderDiv">
    <h3><s:text name="checkout.order.title"/></h3>
    <table id="checkoutTable" class="alt">
        <thead>
        <tr>
            <td><s:text name="checkout.product.name"/></td>
            <td><s:text name="checkout.product.count"/></td>
            <td><s:text name="checkout.product.price"/></td>
        </tr>
        </thead>

        <tbody>
        <s:iterator value="%{ items.entrySet().iterator()}" var="item" status="sts">
            <tr>
                <td><s:property value="%{ #item.key.name }"/></td>
                <td><s:property value="%{ #item.value }"/></td>
                <td><s:property value="%{ #item.key.specialPrice }"/></td>
            </tr>
        </s:iterator>
        </tbody>
        <tfoot>
        <tr>
            <td><s:text name="checkout.product.sum"/></td>
            <td id="summary"></td>

            <td id="summaryMoney"></td>
        </tr>
        </tfoot>
    </table>
</div>
<div id="checkoutDiv">
    <h3><s:text name="checkout.ck.title"/> </h3>
    <s:form namespace="/customer" action="checkout" id="checkoutForm">
        <s:textfield name="postCode" key="checkout.ck.postcode"/>
        <s:doubleselect
                label="Province"  key="checkout.ck.provinde_city"
                list="provinces"    listKey="id"      listValue="name"
                doubleList="cities" doubleListKey="id" doubleListValue="name"
                name="provinceId" doubleName="cityId"/>
        <s:textarea name="address" key="checkout.ck.address" label="Address" cssStyle="width:20em; height:5em"/>
        <s:textfield name="name" key="checkout.ck.name" label="Name"/>
        <s:textfield name="phone" key="checkout.ck.phone" label="Phone"/>
        <s:textfield name="cellPhone" key="checkout.ck.cell_phone" label="Cell Phone"/>
        <s:textfield name="email" key="checkout.ck.email" label="E-Mail"/>

        <s:select list="#{'1':'Card', '2':'Until Arrived'}" name="payType" key="checkout.ck.pay_type" label="Pay Type"/>
        <s:submit/>
    </s:form>
</div>

</body>
</html>
